package j04zuoye;

import java.util.Arrays;
import java.util.Random;

/*
4，冒泡练习
定义一个包含8个元素的整型数组, 数组元素的值是随机的, 取值范围是[10, 80], 打印数组元素的值, 使用冒泡排序对数组进行排序, 打印排序后的元素的值.
 */
public class J04bublle {
    public static void main(String[] args) {
        Random r = new Random();
        int[] arr = new int[8];
        //生成数组内容
        for (int i = 0; i < 8; i++) {
            arr[i] = r.nextInt(71)+10;
        }
        System.out.println("arr = " + Arrays.toString(arr));

        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.println("arr = " + Arrays.toString(arr));
    }
}

class BubbleTest4 {
    public static void main(String[] args) {
        Random r = new Random();
        //intArr
        int[] arrInt = new int[8];
        for (int i = 0; i < arrInt.length; i++) {
            arrInt[i] = r.nextInt(71) + 10;
        }
        System.out.println("排序前:" + Arrays.toString(arrInt));
        for (int i = 1; i <= arrInt.length; i++) {
            for (int j = 0; j < arrInt.length - i ; j++) {
                if(arrInt[j] > arrInt[j + 1]){
                    int temp = arrInt[j];
                    arrInt[j] = arrInt[j + 1];
                    arrInt[j + 1] = temp;
                }
            }
            System.out.println("第" + i + "次排序,输出结果为:" + Arrays.toString(arrInt));
        }
        System.out.println("排序后:" + Arrays.toString(arrInt));
    }
}

class Test1{
    public static void main(String[] args) {
        int[][][] arr = new int[2][3][4];
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.deepToString(arr));
    }
}